package com.etlmaster.executor.steps.datax;

import java.util.HashMap;
import java.util.Map;

import com.etlmaster.executor.Step;
import com.etlmaster.executor.StepMeta;
import com.etlmaster.executor.annotation.StepInstruction;
import com.etlmaster.executor.utils.DataCollectionUtils;
import com.etlmaster.jdbc.JdbcTemplate;

/**
 * @author Wugf
 * @date 2016-03-08
 */
@StepInstruction("ftpwriter")
public class VfsWriterStep extends Step {
	private VfsWriterStepMeta meta;
	public VfsWriterStep(StepMeta meta) {
		super(meta);
		this.meta=(VfsWriterStepMeta)meta;
		// TODO Auto-generated constructor stub
	}

	@Override
	protected int handle() {
		JdbcTemplate jt = new JdbcTemplate();
		
		
		Map<String, String> data = new HashMap<String, String>();
		String ftpSiteInfo=DataCollectionUtils.fetchFtpSiteInfo(meta.getFtpSite(),jt);
		if(ftpSiteInfo==null||ftpSiteInfo.length()==0||ftpSiteInfo.startsWith("file://"))
		{
			ftpSiteInfo="file://";
		}
		data.put("dir", ftpSiteInfo+meta.getDir());
		data.put("field_split", meta.getField_split());
		data.put("prefix_filename", meta.getPrefix_filename());
		data.put("file_type", meta.getFile_type());
		data.put("encoding", meta.getEncoding());
		data.put("filePart", meta.getFilePart());
		Map<String,String> rtnMap= DataxWriter.runDatax(this.hashCode(), meta.getPluginName(), meta.getVariable("readerjobconf").toString(), data);
		meta.getStepState().getReturnValue().put("logInfo", rtnMap.get("jobInfo"));
		return Integer.valueOf(rtnMap.get("status"));

	}

	@Override
	public boolean stop() {
		// TODO Auto-generated method stub
		return false;
	}

}
